/*
 * PriorBI co., ltd.
 * CopyRight 2009-2010
 */
package com.reportgear.report.model.script;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;

/**
 * 条件表达式计算
 * 
 * @author lexloo
 * @version 1.0 Jan/16/2010
 */
public class ConditionExpression {
	public ConditionExpression() {
	}

	public boolean eval(String expression) {
		try {
			ConditionExprLexer lexer = new ConditionExprLexer(new ANTLRStringStream(expression));
			CommonTokenStream tokens = new CommonTokenStream(lexer);
			ConditionExprParser parser = new ConditionExprParser(tokens);
			return Boolean.parseBoolean(String.valueOf(parser.expr()));
		} catch (Exception ex) {
			return false;
		}
	}
}
